
function Search() {
	var obj = $("input[type='radio']:checked");
	var textValue = $("#inputValue").val();
//	alert(textValue);
	if(obj.val() == "0"){
		ajax_tId(textValue);//调用函数不需要加function
	}else if(obj.val() == "1"){
		ajax_tName(textValue);
	}else if(obj.val() == "2"){
		ajax_tCollege(textValue);
	}
}

function ajax_tId(tId){
	$.ajax({
		url:"/teachers/"+tId,//ad_teachers_main.json
		type:"GET",
		async:true,
		data:{
			//'tId':tId,
		},
		dataType:"json",
		success:function(data){
		//	alert(data.teachers);
			if(data.teachers&&data.code == 200){
				//$("#teachers_table tbody").html("");
				$("#teachers_table tbody").children().remove();
				//$.each(data.teachers,function(key,val){
				//for (var i = 0;i < data.teachers.length;i++){
				//	console.log(data.teachers[key]);
				//	console.log(data.teachers[key].tId);
					var $tab = $('<tr><td>'+data.teachers.tId
					+'</td><td>'+data.teachers.tName
					+'</td><td>'+data.teachers.tCollege
					+'</td><td>'+data.teachers.startweek+'~'+data.teachers.endweek
					+'</td><td><a href="#">删除</a> <a href="#">修改</a></td></tr>');
					$("#teachers_table").append($tab);
				//}
				//alert("cid yes!");
			};
		},
		error:function(){
			alert("no!");
		},	
	});
}

function ajax_tName(tName) {
	$.ajax({
		url: "/teachers/name/" + tName, //ad_teachers_main.json
		type: "GET",
		async: true,
		data: {
			//'tId':tId,
		},
		dataType: "json",
		success: function(data) {
			//	alert(data.teachers);
			if (data.teachers && data.code == 200) {
				//$("#teachers_table tbody").html("");
				$("#teachers_table tbody").children().remove();
				for (var i = 0;i < data.teachers.length;i++){
					//	console.log(data.teachers[key]);
					//	console.log(data.teachers[key].tId);
					var $tab = $('<tr><td>'+data.teachers[i].tId
						+'</td><td>'+data.teachers[i].tName
						+'</td><td>'+data.teachers[i].tCollege
						+'</td><td>'+data.teachers[i].startweek+'~'+data.teachers[i].endweek
						+'</td><td><a href="#">删除</a> <a href="#">修改</a></td></tr>');
					$("#teachers_table").append($tab);
				}
			};
		},
		error: function() {
			alert("no!");
		},
	});
}

function ajax_tCollege(tCollege){
	$.ajax({
		url:"/teachers/college/"+tCollege,//
		type:"GET",
		async:true,
		data:{
			//'tId':tId,
		},
		dataType:"json",
		success:function(data){
			//	alert(data.teachers);
			if(data.teachers&&data.code == 200){
				//$("#teachers_table tbody").html("");
				$("#teachers_table tbody").children().remove();
				for (var i = 0;i < data.teachers.length;i++){
					//	console.log(data.teachers[key]);
					//	console.log(data.teachers[key].tId);
					var $tab = $('<tr><td>'+data.teachers[i].tId
						+'</td><td>'+data.teachers[i].tName
						+'</td><td>'+data.teachers[i].tCollege
						+'</td><td>'+data.teachers[i].startweek+'~'+data.teachers[i].endweek
						+'</td><td><a href="#">删除</a> <a href="#">修改</a></td></tr>');
					$("#teachers_table").append($tab);
				}
				//alert("cid yes!");
			};
		},
		error:function(){
			alert("no!");
		},
	});
}

function addBox(result) {
	//result是一个集合,所以需要先遍历
	//alert("ok");
	$.each(result, function(index, obj) {
		$(".tb4_td1").append(obj['cid']);
		alert("1");
		$(".tb4_td2").append(obj['cname']);
		$(".tb4_td3").append(obj['teacher']);
		$(".tb4_td4").append(obj['startweek']);
	});
}

function increa() {
	var inc = confirm("确定增加该课程？");
	if (inc == true) {
		alert("添加成功！");
	} else {
		alert("已取消");
	}
}

function delet() {
	var del = confirm("确定删除该课程？");
	if (del == true) {
		alert("已删除该课程！");
	} else {
		alert("已取消");
	}
}
/*$('#exampleInputSearch').click(function() { //....
	//alert(1);//...
	var textValue = document.getElementsByName("inputValue")[0].value;
	var choose = null;
	var usr1 = document.getElementsByName("choose");
	for (var i = 0; i < usr1.length; i++) { //遍历Radio
		if (usr1[i].checked) {
			choose = usr1[i].value;
		}
	}
	if (textValue == '') {
		alert("请输入课程号或课程名或授课教师!");
	} else if (choose = "0") {

		alert("0");
		$.ajax({
			type: 'GET', //请求方式
			url: 'classinform.json', //地址，就是json文件的请求路径   '/teachers/'+textValue
			dataType: 'json', //数据类型可以为 text xml json  script  jsonp
			//							data:{
			//								inputValue: $('form input[type=text]').val(),
			//							},
			success: function(result) { //返回的参数就是 action里面所有的有get和set方法的参数
				console.log(result.code);
				var teachers = result.teachers;
				addBox(teachers);
			},
		});

		function addBox(teachers) {
			//result是一个集合,所以需要先遍历
			$.each(teachers, function(index, obj) {
				$("#box").append(
					/*"<td class='tb4_td1'>" + obj['tId'] + "</td>" +
					"<td class='tb4_td2'>" + obj['tName'] + "</td>" +
					"<td class='tb4_td3'>" + obj['tCollege'] + "</td>" +
					"<td class='tb4_td4'>" + obj['startweek'] + "~" + obj['endweek'] + "</td>" +
					"<td class='tb4_td5'><a href='#'>删除</a> <a href='#'>修改</a></td>");*/
				/*	"<td class='tb4_td1'>" + obj['cid'] + "</td>" +
					"<td class='tb4_td2'>" + obj['cname'] + "</td>" +
					"<td class='tb4_td3'>" + obj['teacher'] + "</td>" +
					"<td class='tb4_td4'>" + obj['startweek'] + "~" + obj['endweek'] + "周</td>" +
					"<td class='tb4_td5'><a href='#'>删除</a> <a href='#'>修改</a></td>");
			});
		}
	} else {    */
		/*$.ajax({
			type: 'POST',
			url: '/users',
			dataType: "json",
			async: false,
			//					data: $('#form1').serialize(),
			data: {
				usrid: $('form input[type=text]').val(),
				pwd: $('form input[type=password]').val(),
				auth: $('form input[type=radio]').val(),
			},
			error: function(result) {
				console.log(result.code);
				alert('系统错误，请联系管理员 ');
			},
			success: function(result) {
				console.log(result.code);
				if (result.code == "200") {
					console.log(result.code);
					var dataObj = result;
					if (auth == "3") {
						window.open("index.html");
						//    window.location.href = "index.html";
					} else if (auth == "2") {
						window.open("t_ index.html");
					} else if (auth == "1") {
						window.open("index_admin.html");
					}
					alert("hhh");
				} else {
					alert("登录失败！请检查您的账号和密码！");
				}
			},
		});*/
/*		alert("hahh");
	}
});*/